<?php
/**
 * River item class.
 *
 * @package    Elgg.Core
 * @subpackage Core
 * 
 * @property int    $id            The unique identifier (read-only)
 * @property int    $subject_guid  The GUID of the actor
 * @property int    $object_guid   The GUID of the object
 * @property int    $annotation_id The ID of the annotation involved in the action
 * @property string $type          The type of one of the entities involved in the action
 * @property string $subtype       The subtype of one of the entities involved in the action
 * @property string $action_type   The name of the action
 * @property string $view          The view for displaying this river item
 * @property int    $access_id     The visibility of the river item
 * @property int    $posted        UNIX timestamp when the action occurred
 */
class ElggGolfScoreItem {
	
	public $id;
	public $golf_score_id;
	public $golf_course_id;
	public $user_entity_id;
	public $tee;
	public $total_score;
	public $esc_adjustment_total_score;
	public $course_rating;
	public $course_slope;
	public $holes_played;
	public $score_type;
	public $input_date;
	public $update_date;
	
	public $course_name;
	public $golf_course;
	public $user_full_name;

	/**
	 * Construct a river item object given a database row.
	 *
	 * @param stdClass $object Object obtained from database
	 */
	function __construct($object) {
		if (!($object instanceof stdClass)) {
			// throw exception
		}

		// the casting is to support typed serialization like json
		$int_types = array('golf_score_id', 'golf_course_id', 'user_entity_id', 'total_score', 'esc_adjustment_total_score', 'course_slope', 'holes_played', 'score_type');
		$float_types = array('course_rating');
		$date_types = array('input_date', 'update_date');
		foreach ($object as $key => $value) {
			if (in_array($key, $int_types)) {
				$this->$key = (int)$value;
				if($key == 'golf_score_id') {
					$this->id = (int)$value;
				}
			} else if (in_array($key, $float_types)) {
				$this->$key = (float)$value;
			} else if (in_array($key, $date_types)) {
				$this->$key = date('Y-m-d', strtotime($value));
			} else {
				$this->$key = $value;
			}
		}
	}

	/**
	 * Get the subject of this river item
	 * 
	 * @return ElggEntity
	 */
	public function getGolfScoreDetails() {
		return get_entity($this->subject_guid);
	}
	
	public function getType() {
		return 'golfscore';
	}
	
	/**
	 * Get the subtype of the object
	 *
	 * @return string 'item'
	 */
	public function getSubtype() {
		return 'item';
	}
	
	public function getView() {
		return 'item';
	}
	
	public function getSubjectEntity() {
		return $this->user_entity_id;
	}
	
	public function getObjectEntity() {
		return null;
	}

}
